import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)


const routes = [{
		path: '/',
		name: 'login',
		component: () => import( /* webpackChunkName: "about" */ '../views/login.vue')
	},
	{
		path: '/home',
		name: 'home',
		meta: {
			requireAuth: true
		},
		component: () => import( /* webpackChunkName: "about" */ '../views/home.vue'),
	},
	{
		path: '/admin',
		name: 'admin',
		meta: {
			requireAuth: true
		},
		component: () => import( /* webpackChunkName: "about" */ '../views/admin.vue'),
	},
	{
		path: '/main',
		name: 'main',
		meta: {
			requireAuth: true
		},
		component: () => import( /* webpackChunkName: "about" */ '../views/main.vue'),
		children: [
			{
				path: '/other',
				name: 'other',
				meta: {
					requireAuth: true
				},
				component: () => import( /* webpackChunkName: "about" */ '../views/other.vue')
			},
			{
				path: '/dataTotal',
				name: 'dataTotal',
				meta: {
					requireAuth: true
				},
				component: () => import( /* webpackChunkName: "about" */ '../views/dataTotal.vue'),
			},
			{
				path: '/detail',
				name: 'detail',
				meta: {
					requireAuth: true
				},
				component: () => import( /* webpackChunkName: "about" */ '../views/detail.vue'),
			},
			{
				path: '/checkLog',
				name: 'checkLog',
				meta: {
					requireAuth: true
				},
				component: () => import( /* webpackChunkName: "about" */ '../views/checkLog.vue'),
			},
			{
				path: '/account',
				name: 'account',
				meta: {
					requireAuth: true
				},
				component: () => import( /* webpackChunkName: "about" */ '../views/account.vue'),
			},
		]
	},
	{
		path: '/register',
		name: 'register',
		meta: {
			requireAuth: true
		},
		component: () => import( /* webpackChunkName: "about" */ '../views/other.vue')
	},
]

const router = new VueRouter({
	routes
})

// // 全局路由守卫
// router.beforeEach((to, from, next) => {
//   // next();  
//   // // 判断该路由是否需要登录权限 因为在没有token的时候除了登录页面
//   //不用拦截其他都要拦截所以判断要去取反  
//   if (to.meta.requireAuth) { 
//     if(sessionStorage.getItem('token')!=null){ //判断本地是否存在token
//       next();
//     }else {
//       next({
//         path:'/'
//       })
//     }
//   }
// });


export default router
